package com.acme.bankapp.networking;

import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.service.bank.Configuration;

import java.io.*;
import java.net.Socket;

/**
 * Created by Student on 19.11.2014.
 */
public class BankClient {

    public static void main(String[] args) {
        try(Socket s = new Socket("127.0.0.1", Configuration.getPort())){

            try(ObjectInputStream in = new ObjectInputStream(s.getInputStream());
                DataOutputStream out = new DataOutputStream(s.getOutputStream());
                BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
            ) {
                String line = null;
                while (!(line = console.readLine()).equals("exit")) {
                    out.writeUTF(line);
                    switch (line) {
                        case "getClients":
                            Client[] clients = (Client[]) in.readObject();
                            if (clients != null) {
                                for (Client client: clients) {
                                    System.out.println(client);
                                }
                            }
                            break;
                        case "halt":
                            break;
                        default:
                            System.out.println("Unknown command");
                    }

                }


            }catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
